package com.ecoolex.chinadutyfree.retailer.ws;

import java.math.BigDecimal;
import java.util.Date;

import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import com.ecoolex.chinadutyfree.retailer.core.manager.CouponClassExpireStrategyManager;
import com.ecoolex.chinadutyfree.retailer.core.manager.CouponClassManager;
import com.ecoolex.chinadutyfree.retailer.core.manager.CouponManager;
import com.ecoolex.chinadutyfree.retailer.core.manager.CouponVerifyingConsumptionManager;
import com.ecoolex.chinadutyfree.retailer.entity.Coupon;
import com.ecoolex.chinadutyfree.retailer.entity.CouponClass;
import com.ecoolex.chinadutyfree.retailer.entity.CouponClassExpireStrategy;
import com.ecoolex.chinadutyfree.retailer.entity.CouponVerifyingConsumption;
import com.ecoolex.chinadutyfree.retailer.pojo.EditCouponClassStep;
import com.ecoolex.chinadutyfree.retailer.pojo.QueryCouponClassDTO;
import com.ecoolex.chinadutyfree.retailer.pojo.QueryCouponDTO;
import com.ecoolex.framework.common.exception.BizException;
import com.ecoolex.framework.common.pojo.Page;
import com.ecoolex.framework.common.pojo.Pagination;
import com.ecoolex.framework.common.pojo.Sorting;

@Service
public class CouponServiceImpl implements CouponService{
	
	@Autowired
	private CouponClassManager couponClassManager;

	@Override
	public Pagination<CouponClass> queryCouponClass(QueryCouponClassDTO query, Page page) {
		return couponClassManager.queryCouponClass(query, page);
	}

	@Override
	public Pagination<CouponClass> queryCouponClassForUser(Page page) {
		return couponClassManager.queryCouponClassForUser(page);
	}
	
	@Override
	public CouponClass getCouponClassById(Integer couponClassId) {
		return couponClassManager.getCouponClassById(couponClassId);
	}

	@Override
	public Boolean deleteCouponClass(CouponClass couponClass, String updateUser) {
		return couponClassManager.deleteCouponClass(couponClass, updateUser);
	}

	@Override
	public CouponClass updateCouponClassStep(EditCouponClassStep step, String updateUser) throws BizException {
		return couponClassManager.updateCouponClassStep(step, updateUser);
	}

	@Override
	public Boolean onlineCouponClass(CouponClass couponClass, String updateUser) {
		return couponClassManager.onlineCouponClass(couponClass, updateUser);
	}

	@Override
	public Boolean invalidCouponClass(CouponClass couponClass, String updateUser) {
		return couponClassManager.invalidCouponClass(couponClass, updateUser);
	}

	@Override
	public Boolean updateCouponClassProvideNumber(CouponClass couponClass, Integer newProvideNumber, String updateUser) {
		return couponClassManager.updateCouponClassProvideNumber(couponClass, newProvideNumber, updateUser);
	}
	
	@Autowired
    private CouponClassExpireStrategyManager couponClassExpireStrategyManager;

	@Override
	public CouponClassExpireStrategy getCouponClassExpireStrategyById(Integer couponClassId) {
		return couponClassExpireStrategyManager.getByCouponClassId(couponClassId);
	}
	
	@Autowired
	private CouponManager couponManager;

	@Override
	public Coupon getByUserIdAndCouponClassId(Integer userId, Integer couponClassId) {
		return couponManager.getByUserIdAndCouponClassId(userId, couponClassId);
	}

	@Override
	public Coupon receiveCoupon(Integer couponClassId, Integer userId, String createUser) {
		return couponManager.receiveCoupon(couponClassId, userId, createUser);
	}

	@Override
	public Pagination<Coupon> couponList(Integer userId, Page page) {
		return couponManager.couponList(userId, page);
	}

	@Override
	public Pagination<Coupon> couponList(QueryCouponDTO query, Sorting[] sorts, Page page) {
		return couponManager.couponList(query, sorts, page);
	}
	
	@Override
	public Boolean checkCoupon(Date createTime,BigDecimal realPrice, Integer couponId) {
		return couponManager.verifyCoupon(createTime,realPrice,couponId);
	}
	
	@Autowired
	private CouponVerifyingConsumptionManager couponVerifyingConsumptionManager;

	@Override
	public CouponVerifyingConsumption getCouponVerifyingConsumptionByCouponId(Integer couponId) {
		return couponVerifyingConsumptionManager.getCouponVerifyingConsumptionByCouponId(couponId);
	}

}
